package com.atguigu.demojuc.chap01;

//1.extends Thread
class T1 extends Thread{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "\t" + "---come in");
    }
}

//2.implements Runnable
class T2 implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "\t" + "---come in");
    }
}

/**
 * 线程创建方式：
 *      1.extends Thread
 *      2.implements Runnable
 *      3.implements Callable
 *      4.ThreadPoolExecutor
 */
public class ThreadDemo {
    public static void main(String[] args) {
/*        T1 t1 = new T1();
        t1.setName("t1");
        //t1.run(); //错误演示
        t1.start(); //现在正确启动方式 调用 private native void start0(); 方法，调用操作系统底层线程运行线程(CPU分配时间片)
        //t1.start(); //java.lang.IllegalThreadStateException  线程不能启动多次。注意：线程6个状态*/

        //创建两个线程对象，使用同一个Runnable对象，可以启动线程多次。
/*        Runnable runnable = new T2();
        //t2.run();  //错误演示
        Thread t2 = new Thread(runnable,"t2");
        t2.start();


        Thread t3 = new Thread(runnable,"t3");
        t3.start();*/

        //匿名内部类写法
/*        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "\t" + "---come in");
            }
        }, "t4").start();*/

        //lambada表达式写法
        new Thread(()->System.out.println(Thread.currentThread().getName() + "\t" + "---come in"), "t5").start();
    }
}
